package com.cloud.order.service;

import com.cloud.order.api.ProductApi;
import com.cloud.order.mapper.OrderMapper;
import com.cloud.order.model.OrderInfo;

import com.cloud.product.model.ProductInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

@Service
public class OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private ProductApi productApi;
 public OrderInfo selectByOrderId(Integer orderId) {
     OrderInfo orderInfo = orderMapper.selectById(orderId);
//     String url = "http://prodect-service/product/"+orderInfo.getProductId();
//     ProductInfo productInfo = restTemplate.getForObject(url,ProductInfo.class);
     ProductInfo productInfo = productApi.getProductById(orderInfo.getProductId());
     orderInfo.setProductInfo(productInfo);
     return orderInfo;
 }
}
